package com.log.demo.controller;

import com.log.demo.dto.ErrorCode;
import com.log.demo.dto.RequstDto;
import com.log.demo.dto.ResultMsg;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

/**
 * @author weijinhao
 * @date 2023/11/18 16:57
 */
@Slf4j
@RestController
public class TestController {
    @PostMapping("/revice")
    public ResultMsg revice(RequstDto dto) {
       return tmp();
    }

    @PostMapping("/query")
    public ResultMsg query(RequstDto dto) {
        return tmp();
    }

    @PostMapping("/callback")
    public ResultMsg callback(RequstDto dto) {
        return tmp();
    }

    @PostMapping("/sign")
    public ResultMsg sign(RequstDto dto) {
        return tmp();
    }

    @PostMapping("/refund")
    public ResultMsg refund(RequstDto dto) {
        return tmp();
    }
    private ResultMsg tmp () {
        log.info("this is come in");
        int i = new Random().nextInt(10);
        if( i > 7) {
            //抛出一场
            if(new Random().nextInt(10) > 3) {
                return ResultMsg.other(ErrorCode.notsign,null);
            }else {
                int i1 = new Random().nextInt(10);
                if(i1 >= 5) {
                    return ResultMsg.other(ErrorCode.nomoney,null);
                }else if(i1 < 5 && i1 > 3) {
                    return ResultMsg.other(ErrorCode.unsaft,null);
                }else {
                    return ResultMsg.other(ErrorCode.fail,null);
                }
            }
        }
        return  ResultMsg.success(null);
    }





}

